package cn.jtfadmin.base.shiro.statuscode;

import cn.jtfadmin.base.lang.config.WebConfig;
import cn.jtfadmin.base.lang.config.statuscode.ExceptionStatusCodeConfig;
import cn.jtfadmin.base.lang.config.statuscode.ExceptionStatusDescribe;
import cn.jtfadmin.base.lang.config.statuscode.StatusCodeConfig;
import cn.jtfadmin.base.lang.config.statuscode.StatusCodeManager;
import org.apache.shiro.authc.DisabledAccountException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 未认证 错误码
 *
 * @author jtf
 * @see StatusCodeConfig
 * @see StatusCodeManager
 * @see WebConfig#configureHandlerExceptionResolvers(List)
 * @since 0.0.1
 */
@Component
public class NoAuthorityStatusCodeConfig implements ExceptionStatusCodeConfig {

    /**
     * 用户名或密码错误
     */
    public static final Integer USERNAME_OR_PWD_ERROR = 501;
    /**
     * 登录失效或未授权
     */
    public static final Integer NO_AUTHORITY_CODE = 401;


    /**
     * 用户禁用错误码
     */
    public static final Integer USER_DISABLED = 403;


    @Override
    public Set<ExceptionStatusDescribe> getExStatusDecribes() {
        Set<ExceptionStatusDescribe> set = new HashSet<>();
        set.add(new ExceptionStatusDescribe("登录失效或未授权", NO_AUTHORITY_CODE, UnknownAccountException.class));//
        set.add(new ExceptionStatusDescribe("用户名或密码错误", USERNAME_OR_PWD_ERROR, IncorrectCredentialsException.class));//
        set.add(new ExceptionStatusDescribe("用户被禁用", USER_DISABLED, DisabledAccountException.class));//
        return set;
    }


}
